home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Streams.h
-
- Contains: xxx put contents here xxx
-
- Written by: Essam Zaky
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 1/4/94 EZ clean up
- <1> 1/4/94 EZ first checked in
-
- */
-
- #ifndef _Streams_
- #define _Streams_
-
- #ifndef _ToolBoxDump_
- #include "ToolBoxDump.h"
- #endif
-
- #ifndef _TextensionCommon_
- #include "TextensionCommon.h"
- #endif
-
- #ifndef _Array_
- #include "Array.h"
- #endif
- //***************************************************************************************************
-
- class CStream : public HandleObject {
- public:
- CStream();
-
- void IStream();
- virtual void Free();
-
- virtual OSErr WriteBytes(const void* theBytes, long bytesCount) = 0;
- virtual OSErr ReadBytes(void* theBytes, long bytesCount) = 0;
-
- inline OSErr WriteChar(char theChar) {return this->WriteBytes(&theChar, sizeof(theChar));}
- inline OSErr WriteBoolean(Boolean theBoolean) {return this->WriteBytes(&theBoolean, sizeof(theBoolean));}
- inline OSErr WriteShort(short theShort) {return this->WriteBytes(&theShort, sizeof(theShort));}
- inline OSErr WriteLong(long theLong) {return this->WriteBytes(&theLong, sizeof(theLong));}
- inline OSErr WritePoint(Point thePoint) {return this->WriteBytes(&thePoint, sizeof(thePoint));}
- inline OSErr WriteRect(const Rect* theRect) {return this->WriteBytes(theRect, sizeof(Rect));}
-
- #ifdef txtnNever
- OSErr WriteHandle(Handle theHandle);
- //writes the handleSize then handlebytes
- #endif
-
- inline OSErr ReadChar(char* theChar) {return this->ReadBytes(theChar, sizeof(char));}
- inline OSErr ReadBoolean(Boolean* theBoolean) {return this->ReadBytes(theBoolean, sizeof(Boolean));}
- inline OSErr ReadShort(short* theShort) {return this->ReadBytes(theShort, sizeof(short));}
- inline OSErr ReadLong(long* theLong) {return this->ReadBytes(theLong, sizeof(long));}
- inline OSErr ReadPoint(Point* thePoint) {return this->ReadBytes(thePoint, sizeof(Point));}
- inline OSErr ReadRect(Rect* theRect) {return this->ReadBytes(theRect, sizeof(Rect));}
-
- #ifdef txtnNever
- OSErr ReadHandle(Handle* theHandle);
- //creates a new handle Reads the handleSize then handlebytes
- #endif
-
- virtual long GetPosition() const;
- virtual void SetPosition(long newPosition);
- virtual void Skip(long count);
-
- virtual long GetSize() const = 0;
-
- virtual OSErr Append(long count) = 0;
- //Appends "count" bytes at the end of the stream, position is not changed
-
- virtual void Empty();
-
- virtual OSErr Load(long size, Ptr* data) = 0; //fPosition is advanced by "size"
- virtual void Unload(Ptr data) = 0; //should be called even if "Load" returns an error
-
- protected:
- long fPosition;
-
- private:
- };
- //***************************************************************************************************
-
- /*CHandleStream could be declared as public CStream, public CArray, but can't have multiple inheritance!*/
-
- class CHandleStream : public CStream {
- public:
- CHandleStream();
-
- void IHandleStream();
-
- //•override
- virtual void Free();
-
- virtual OSErr WriteBytes(const void* theBytes, long bytesCount);
- virtual OSErr ReadBytes(void* theBytes, long bytesCount);
-
- virtual long GetSize() const;
-
- virtual OSErr Append(long count);
-
- virtual void Empty();
-
- virtual OSErr Load(long size, Ptr* data);
- virtual void Unload(Ptr data);
-
- //•own
-
- inline Ptr GetStreamPtr() {return Ptr(fArray->GetElementPtr(0));}
-
- inline void* LockStream(Boolean moveHi = false) {return fArray->LockArray(moveHi);}
- inline void UnlockStream() {fArray->UnlockArray();}
-
- protected:
-
- private:
- CArray* fArray;
- };
- //***************************************************************************************************
-
- #endif
-